#include <REGX52.H>
/**
 * 流水灯按照矩形的顺序流动
 */
void delay_ms(unsigned int ms)
{
    unsigned int i, j;
    for (i = 0; i < ms; i++)
    {
        for (j = 0; j < 123; j++)
            ;
    }
}

void main()
{
    unsigned char i;
    P2 = 0xFF;
    P3 = 0x00;
    while (1)
    {
        for (i = 0; i < 8; i++)
        {
            P2 = ~(0x01 << i);
            delay_ms(200);
        }
        P2 = 0xFF;

        for (i = 0; i < 8; i++)
        {
            P3 = (0x01 << i);
            delay_ms(200);
        }
        P3 = 0x00;
    }
}